﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using Server_NhaSach.DataTransferObject;
using Server_NhaSach.DataAccess.HelperLayer;
namespace Server_NhaSach.DataAccess.LogicLayer
{
    [Serializable]
    public class PhieuDatHangNCCADO
    {
        #region "Khai báo các biến"
        private Helper helper;
        private string _error;
        #endregion
        #region "Khai báo các thuộc tính"
        public string Error
        {
            get { return _error; }
        }
        #endregion
        #region "Khai báo các Method"
        public bool InsertPhieuDHNCC(PhieuDatHangNCCDTO PhieuDH)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[11];
            par[0] = new SqlParameter("@MaDHNCC", PhieuDH.MaDHNCC);
            par[1] = new SqlParameter("@MaNV", PhieuDH.MaNV);
            par[2] = new SqlParameter("@MaKho", PhieuDH.MaKho);
            par[3] = new SqlParameter("@MaNCC", PhieuDH.MaNCC);
            par[4] = new SqlParameter("@SoChungTuDH", PhieuDH.SoChungTuDH);
            par[5] = new SqlParameter("@NgayThangDH", PhieuDH.NgayThangDH);
            par[6] = new SqlParameter("@GhiChuDH", PhieuDH.GhiChuDH);
            par[7] = new SqlParameter("@TongDonHang", PhieuDH.TongDonHang);
            par[8] = new SqlParameter("@TamUng", PhieuDH.Tamung);
            par[9] = new SqlParameter("@ConLai", PhieuDH.ConLai);
            par[10] = new SqlParameter("@NgayBanGiao", PhieuDH.NgayBanGiao);
            try
            {
                helper.InsertQuery("sp_Insert_PhieuDatHangNCC", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public bool UpdatePhieuDHNCC(PhieuDatHangNCCDTO PhieuDH)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[11];
            par[0] = new SqlParameter("@MaDHNCC", PhieuDH.MaDHNCC);
            par[1] = new SqlParameter("@MaNV", PhieuDH.MaNV);
            par[2] = new SqlParameter("@MaKho", PhieuDH.MaKho);
            par[3] = new SqlParameter("@MaNCC", PhieuDH.MaNCC);
            par[4] = new SqlParameter("@SoChungTuDH", PhieuDH.SoChungTuDH);
            par[5] = new SqlParameter("@NgayThangDH", PhieuDH.NgayThangDH);
            par[6] = new SqlParameter("@GhiChuDH", PhieuDH.GhiChuDH);
            par[7] = new SqlParameter("@TongDonHang", PhieuDH.TongDonHang);
            par[8] = new SqlParameter("@TamUng", PhieuDH.Tamung);
            par[9] = new SqlParameter("@ConLai", PhieuDH.ConLai);
            par[10] = new SqlParameter("@NgayBanGiao", PhieuDH.NgayBanGiao);
            try
            {
                helper.UpdateQuery("sp_Update_PhieuDatHangNCC", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public bool DeletePhieuDHNCC(string MaDHNCC)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[1];
            par[0] = new SqlParameter("@MaDHNCC", MaDHNCC);
            try
            {
                helper.DeleteQuery("sp_Delete_PhieuDatHangNCC", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public DataSet LayDS_PhieuDHNCC()
        {
            helper = new Helper();
            DataSet ds_PhieuDHNCC = helper.SelectQuery("sp_LayDS_PhieuDatHangNCC");
            return ds_PhieuDHNCC;
        }
        #endregion
    }
}